home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / IM_3 .adf / Exec / piarc.LZH / targaw.rexx < prev    next >
OS/2 REXX Batch file  |  1992-04-09  |  5KB  |  204 lines

  1. /*
  2.  * targaw.rexx
  3.  *
  4.  *  Written by: Pete Patterson & Ben Williams
  5.  * Last Update: April 18, 1992
  6.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  7.  * ---------------------------------------------------------------------------
  8.  *    Revision: 1.02
  9.  */
  10.  
  11. /*
  12.  * open rexxsupport.library -- needed for some functions
  13.  */
  14. if ~show('L',"rexxsupport.library") then do
  15.   if addlib('rexxsupport.library',0,-30,0) then do
  16.       /* everything's ok */
  17.     end;
  18.   else do
  19.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  20.     say 'Cannot operate targaw.rexx without this library - sorry!';
  21.     exit 10;
  22.     end;
  23.   end;
  24.  
  25. /*
  26.  * This will automatically direct the script to the proper
  27.  * software, if it is running.
  28.  */
  29. prtnme = 'IP_Port'; /* assume Image Professional */
  30. if show('P','IP_Port') = 0 then do
  31.   if show('P','IM_Port') = 0 then do
  32.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  33.     say "This script requires IP, IM or IM F/c to run!";
  34.     exit(20);
  35.     end;
  36.   else do
  37.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  38.     end;                 /* We make em, user's break em.          */
  39.   end;
  40.  
  41.   /*
  42.    * This code attempts to read a file called "picmdpath" from REXX:
  43.    * If it can't find it, the script will assume that the commands
  44.    * associated with this PI Module are in "c:". If the file exists,
  45.    * the script will look in the path that is specified in the file.
  46.    * If you create this file, you MUST put a complete, correct path
  47.    * in it; if the commands are in a sub-directory, you have to put
  48.    * the trailing slash on the path (like, device:dir/).
  49.    * 
  50.    */
  51.   cmdpath = 'c:';
  52.   if open(fhandle,'rexx:picmdpath','read') then  /* open the file */
  53.     do
  54.       cmdpath = readln(fhandle);
  55.       call close(fhandle);  /* close the file    */
  56.     end
  57.  
  58. options;
  59. address;
  60.  
  61.   prevpath = 'ram:'; /* put user in ram to start with... */
  62.  
  63.   if show('C',targapath) = 1 then do
  64.     prevpath = getclip(targapath);
  65.     end;
  66.  
  67.   address(prtnme);
  68.   options results;
  69.   'current';
  70.   bufdata = result; /* get name of buffer, if there is one */
  71.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum;
  72.   if bname ~= '<none>' then do
  73.     bufname = bname;
  74.     end;
  75.   if (length(bufname) > 4) then do
  76.     epos = pos('.tga',bufname,length(bufname)-3);
  77.     if epos ~= 0 then do
  78.       bufname = left(bufname,epos-1)
  79.       end
  80.     end;
  81.   'filerequest "'||prevpath||'","'||bufname||'",".tga","Save TARGA"';
  82.   TARGAfile = result;
  83.   options;
  84.  
  85.   if TARGAfile = 'FR_CANCELLED' then do
  86.     address(prtnme);
  87.     'imtofront';
  88.     exit 0;
  89.     end;
  90.  
  91.   TARGAfile = expandfilename(TARGAfile);
  92.   thispath = gimmepath(TARGAfile);
  93.   call setclip(targapath,thispath);
  94.  
  95.   address(prtnme);
  96.  
  97. 'tofront';
  98.  
  99. options results;
  100. 'gadgets "16 Bit","Targa","24 Bit","Targa","32 Bit","Targa"';
  101. pxsz = result-1;
  102. options;
  103. if pxsz < 0 then do
  104.   address;
  105.   exit 0;
  106.   end
  107.  
  108. options results;
  109. 'gadgets "Compressed","Data","No","Compression"';
  110. comp = result-1;
  111. options;
  112. if comp < 0 then do
  113.   address;
  114.   exit 0;
  115.   end
  116.  
  117. /*
  118. options results;
  119. 'gadgets "Use","Color Table","No","Color Table"';
  120. tbl = result-1;
  121. options;
  122. if tbl < 0 then do
  123.   address;
  124.   exit 0;
  125.   end;
  126.  
  127. ptype = 0;
  128. if comp = 1 & tbl = 0 then ptype = 1;
  129. if comp = 1 & tbl = 1 then ptype = 2;
  130. if comp = 0 & tbl = 0 then ptype = 9;
  131. if comp = 0 & tbl = 1 then ptype = 10;
  132. */
  133. ptype = 0;
  134. if comp = 1 then ptype = 2;
  135. if comp = 0 then ptype = 10;
  136.  
  137.   options results;
  138.   'jackin';
  139.   jackadr = result;
  140.   options;
  141.  
  142.   'wbtofront';
  143.   'lockimage '||bnum;
  144.   address command cmdpath||'targaw '||jackadr||' '||ptype||' '||pxsz||' "'||TARGAfile||'"';
  145.   'unlockimage '||bnum;
  146.  
  147.   address(prtnme);
  148.   'imtofront';
  149.   address;
  150.  
  151.   exit 0;
  152.  
  153. /*
  154.  * gimmepath
  155.  *
  156.  * This takes the provided argument and sucks the path out of it, then
  157.  * returns that path to the caller, sans file name.
  158.  */
  159. gimmepath:
  160.   arg fullnamegx;
  161.     tempgx = reverse(fullnamegx);
  162.     lengx = length(fullnamegx);   /* get length of string */
  163.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  164.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  165.     seploc = 0; /* assumes current dir, no path supplied */
  166.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  167.       seploc = (lengx - slashdex)+1;
  168.       end;
  169.     else do
  170.       if colondex ~= 0 then do /* we assume we are on a device */
  171.         seploc = (lengx - colondex)+1;
  172.         end;
  173.       end;
  174.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  175.   gxpath = left(fullnamegx,seploc);
  176.   return(gxpath);
  177.  
  178. /*
  179.  * Since this script can't be expected to know where the CD of the user
  180.  * is when this cmd is invoked, we have to check the path the user
  181.  * provides - if it's not specified right from a root, then we have
  182.  * to make it a complete specification from the root.
  183.  */
  184. expandfilename:
  185.   parse arg jfile;
  186.   if index(jfile,':') = 0 then do
  187.     curdir = pragma(D);
  188.     if right(curdir,1) ~= ':' then do
  189.       if right(curdir,1) ~= '/' then do
  190.         if curdir ~= '' then do
  191.           curdir = curdir || '/';
  192.           end;
  193.         end;
  194.       end;
  195.     jfile = curdir||jfile;
  196.     end;
  197.   return(jfile);
  198.  
  199. rvalue:
  200.   wordnum = c2d(readch(fhandle,1)) * 256;
  201.   wordnum = wordnum + c2d(readch(fhandle,1));
  202.   return wordnum;
  203.  
  204.